﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Data.SqlClient;



/// <summary>
/// RxjhClass 的摘要说明
/// </summary>
public class AdminClass
{
    public AdminClass()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    //public static int aabbcc()
    //{
    //    try
    //    {
    //        SymmetricMethod md5 = new SymmetricMethod();
    //        string kke = md5.Decrypto(ConfigurationManager.AppSettings["LicenseKey"]);
    //        string host = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
    //        if (kke == "")
    //        {
    //            return 0;
    //        }
    //        string[] ddd = kke.Split('|');
    //        string[] ccc = ddd[0].Split(',');
    //        bool eee = false;
    //        for (int i = 0; i < ccc.Length; i++)
    //        {
    //            if (host.IndexOf(ccc[i]) != -1)
    //            {
    //                eee = true;
    //            }
    //        }
    //        if (!eee)
    //        {
    //            return 0;
    //        }
    //        return 1;
    //    }
    //    catch
    //    {
    //        return 0;
    //    }
    //}

    //public static int MyCallBack()
    //{
    //    //SymmetricMethod md5 = new SymmetricMethod();
    //    //string kke = md5.Decrypto(ConfigurationManager.AppSettings["LicenseKey"]);
    //    //string host = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
    //    //if (kke == "")
    //    //{
    //    //    HttpContext.Current.Response.Write(host + " " + SymmetricMethod.GetIP());
    //    //    HttpContext.Current.Response.End();
    //    //    return 0;
    //    //}
    //    //string[] ddd = kke.Split('|');
    //    //string[] ccc = ddd[0].Split(',');
    //    //bool eee = false;
    //    //for (int i = 0; i < ccc.Length; i++)
    //    //{
    //    //    if (host.IndexOf(ccc[i]) != -1)
    //    //    {
    //    //        eee = true;
    //    //    }
    //    //}
    //    //if (!eee)
    //    //{
    //    //    HttpContext.Current.Response.Write(host + "-" + SymmetricMethod.GetIP());
    //    //    HttpContext.Current.Response.End();
    //    //    return 0;
    //    //}

    //    return aabbcc();
    //}
    public static string Getsh(string sh, string id)
    {
        if (sh == "0")
        {
            return ("<a class='black' href='admin_Post.aspx?id=" + id + "&type=sh'>通过</a>");
        }
        return ("<a class='black' href='admin_Post.aspx?id=" + id + "&type=bsh'>取消</a>");
    }

    public static string cutString(string strInput, int intLen)
    {
        strInput = strInput.Trim();
        if (Encoding.Default.GetBytes(strInput).Length <= intLen)
        {
            return strInput;
        }
        string s = "";
        string str2 = "";
        for (int i = 0; i < strInput.Length; i++)
        {
            if (Encoding.Default.GetBytes(s).Length >= (intLen - 4))
            {
                break;
            }
            s = s + strInput.Substring(i, 1);
        }
        str2 = "<img src=\"images/sys_bg85.gif\" href=\"#\" onMouseOver=\"fnDef();\" title=\"" + strInput + "\">";
        return (s + str2);
    }






    public static void aacc()
    {
        //try
        //{
        //    SymmetricMethod md5 = new SymmetricMethod();
        //    string kke = md5.Decrypto(ConfigurationManager.AppSettings["LicenseKey"]);
        //    string host = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
        //    if (kke == "")
        //    {
        //        HttpContext.Current.Response.Write(host + " " + SymmetricMethod.GetIP());
        //        HttpContext.Current.Response.End();
        //    }
        //    string[] ddd = kke.Split('|');
        //    string[] ccc = ddd[0].Split(',');
        //    bool eee = false;
        //    for (int i = 0; i < ccc.Length; i++)
        //    {
        //        if (host.IndexOf(ccc[i]) != -1)
        //        {
        //            eee = true;
        //        }
        //    }
        //    if (!eee)
        //    {
        //        HttpContext.Current.Response.Write(host + "-" + SymmetricMethod.GetIP());
        //        HttpContext.Current.Response.End();
        //    }
        //}
        //catch
        //{

        //    HttpContext.Current.Response.End();
        //}
    }

    public static bool GetUser(string id, string pwd)
    {
        string sql = string.Format("select id from Admin where name=@UserId and pwd=@UserPwd");

        SqlParameter[] prams = {
            SqlDBA.MakeInParam("@UserId", SqlDbType.VarChar, 10, id),
            SqlDBA.MakeInParam("@UserPwd", SqlDbType.VarChar, 10, pwd)
        };
        DataTable table1 = DBAi.GetDBToDataTable(sql, prams);
        if (table1 != null)
        {
            if (table1.Rows.Count == 0)
            {
                //WebFun.ClientScriptBack("alert('提示：帐号或密码错误，请重新输入！');", true);
                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            //WebFun.ClientScriptBack("alert('提示：帐号或密码错误，请重新输入！');", true);
            return false;
        }
    }
    public static bool GetUserONLINE(string id, string server)
    {
        string sql = string.Format("select FLD_ID,FLD_ONLINE from [TBL_ACCOUNT] where FLD_ID='{0}'", id);
        DataTable table1 = DBA.GetDBToDataTable(sql, "rxjhaccount", server);
        if (table1 != null)
        {
            if (int.Parse(table1.Rows[0]["FLD_ONLINE"].ToString()) == 1)
            {
                table1.Dispose();
                return true;

            }
            else
            {
                table1.Dispose();
                return false;
            }
        }
        else
        {
            table1.Dispose();
            return true;
        }
    }
    public static void SetLog(string 用户, string IP, string 操作类型, string 操作内容)
    {
        string sql = string.Format("INSERT INTO 操作日志(用户,IP,操作类型,操作内容) VALUES('{0}','{1}','{2}','{3}')", 用户, IP, 操作类型, 操作内容);
        DBAi.ExeSqlCommand(sql);
    }
    public static void SetItmeLog(long id, string ItmeName, string name, string sx, string server, string sm)
    {
        string sql = string.Format("INSERT INTO Itme_Log (ItmeId,ItmeName,[name],shuxing,server,sm)values({0},'{1}','{2}','{3}','{4}','{5}')", id, ItmeName, name, sx, server, sm);
        DBAi.ExeSqlCommand(sql);
    }
    public static string ToString(byte[] bytes)
    {
        StringBuilder a1 = new StringBuilder();

        foreach (byte byt in bytes)
        {
            a1.Append(Convert.ToString((short)byt, 16).PadLeft(2, '0').ToUpper());
        }
        return a1.ToString();
    }
    public static void UpItemsDate(string ServerId, string UserName, byte[] Itmes, string SelectDb)
    {
        string DataName = "TBL_XWWL_Char";
        string DataWere = "FLD_ITEM";
        string DataKey = "FLD_NAME";
        int 物品数 = 36;
        if (SelectDb == "0")
        {
            DataName = "TBL_XWWL_Char";
            DataWere = "FLD_ITEM";
            DataKey = "FLD_NAME";
            物品数 = 36;
        }
        else if (SelectDb == "1")
        {
            DataName = "TBL_XWWL_Char";
            DataWere = "FLD_WEARITEM";
            DataKey = "FLD_NAME";
            物品数 = 15;
        }
        else if (SelectDb == "2")
        {
            DataName = "TBL_XWWL_Warehouse";
            DataWere = "FLD_ITEM";
            DataKey = "FLD_NAME";
            物品数 = 60;
        }
        else if (SelectDb == "3")
        {
            DataName = "TBL_XWWL_PublicWarehouse";
            DataWere = "FLD_ITEM";
            DataKey = "FLD_ID";
            物品数 = 60;
        }
        string sql = string.Format("update {0} set {1}=0x{2}  WHERE {3} ='{4}'", DataName, DataWere, ToString(Itmes), DataKey, UserName);
        DBA.ExeSqlCommand(sql, "rxjhgame", ServerId);
    }
    public static string GetItemslist(ItmeSClass ItmeSC, byte[] Itmes, int 物品数)
    {
        Dictionary<int, 物品类> ItmeList = new Dictionary<int, 物品类>();
        for (int i = 0; i < 物品数; i++)
        {
            if (Itmes.Length >= i * 73 + 73)
            {
                byte[] 单个物品 = new byte[73];
                try
                {
                    System.Buffer.BlockCopy(Itmes, i * 73, 单个物品, 0, 73);

                    物品类 物品 = new 物品类(单个物品);
                    ItmeList.Add(i, 物品);

                    ItmeClass Itme = new ItmeClass();
                    Itme.ID = i;
                    Itme.FLD_ID = System.BitConverter.ToInt64(物品.物品全局ID, 0);
                    Itme.FLD_ItmeID = System.BitConverter.ToInt32(物品.物品ID, 0);
                    Itme.FLD_NAME = 物品.物品名称;
                    Itme.FLD_Type = 物品.物品类型;
                    Itme.FLD_Suliang = System.BitConverter.ToInt32(物品.物品数量, 0); ;
                    Itme.FLD_MAGIC0 = 物品.FLD_MAGIC0;
                    Itme.FLD_MAGIC1 = 物品.FLD_MAGIC1;
                    Itme.FLD_MAGIC2 = 物品.FLD_MAGIC2;
                    Itme.FLD_MAGIC3 = 物品.FLD_MAGIC3;
                    Itme.FLD_MAGIC4 = 物品.FLD_MAGIC4;
                    Itme.FLD_CjFh = 物品.FLD_FJ_初级附魂;
                    Itme.FLD_ZjFh = 物品.FLD_FJ_中级附魂;
                    Itme.FLD_JingHua = 物品.FLD_FJ_进化;
                    Itme.FLD_Bind = 物品.物品绑定;
                    ItmeSC.ItmeList.Add(Itme);
                    if (System.BitConverter.ToInt32(物品.物品ID, 0) == 0)
                    {
                        ItmeSC.Kwei++;
                    }
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("提示：数据错误1！" + ex.Message);
                }
            }
        }
        return JsonConvert.SerializeObject(ItmeSC);
    }
}
